package com.kotlin.lib

open class Fruit {
    open val weight: String get() = "FruitWeight"
    open fun name() {//重写父类的当中的某个方法，kotlin父类必须保持open
        println("Fruit")
    }
}

open class Apple : Fruit() {
    override var weight: String = super.weight + " >Apple"
    final override fun name() {//重写父类的当中的某个方法，指定override.final决定child没法重写这个方法了
        super.name()
        println("Apple")
    }
}

class ApplePear : Apple()

//构造方法里定义重写的属性
class Peach(override var weight: String) : Fruit() {
    override fun name() {
        print("peach")
    }
}

interface ParentA {
    fun method() {
        print("A")
    }
}

open class ParentB {
    open fun method() {
        print("B")
    }
}

abstract class AbstractClassC : ParentB() {
    abstract override fun method()//通过抽象方法，把父类的默认实现冲掉
}

class ImplementC : AbstractClassC() {
    override fun method() {
        println("Not yet implemented")
    }
}

class ChildC : ParentA, ParentB() {
    override fun method() {//父类中有两个相同签名的方法
        super<ParentA>.method()
        super<ParentB>.method()
    }
}

fun main() {
    val apple = Apple()//filed的继承和重写
    println(apple.weight)
    println("---------------")
    (apple.name())

    ChildC().method()
    ImplementC().method()
}
